package com.panorama.visitor;


public class PrintVisitor extends AbstractReflectionVisitor<Void> {
	private int tab = -1;
	private String tabString = "";
	
	public PrintVisitor() {
		
	}
	
	public PrintVisitor(int tab) {
		this.tab = tab;
		this.tabString = getTab();
	}
	
	@Override
	public Visitor<Void> enter(VisitableNode node) {
		return new PrintVisitor(tab + 1);
	}
	
	@Override
	public void visit(VisitableNode node) {
		System.out.println(tabString + "Visiting: " + node);
	}
	
	@Override
	public Void leave(VisitableNode node) {
		System.out.println(tabString + "Leaving: " + node);
		
		return super.leave(node);
	}
	
	private String getTab() {
		String tabString = "";
		
		for(int i = 0; i < tab; i++) {
			tabString += "\t";
		}
		
		return tabString;
	}

}
